package robocup.component.actions;

import robocup.component.geometry.Vektor;
import robocup.component.math.RCMath;

/**
 * A kick action is used for player-agents to accelerate the ball.
 */
public class KickAction
    extends Action {

  /**
   * The kick-power, which can be used. Lies within [0,100].
   */
  private double _power;

  /**
   * The direction (relative to the player, in which the ball should be kicked.
   * Any direction is possible (-180,180].
   */
  private double _direction;

  /**
   * Constructor, sets a sepcific kick-command
   * 
   * @param power
   *          the power of the kick [0,100]
   * @param direction
   *          the angle of the kick (-180,180]
   */
  public KickAction(
      final double power,
      final double direction) {

    this._type = TYPE.KICK;
    this._power = RCMath.round(power, Action.PARAMETER_PRECISION);
    this._direction = RCMath.round(direction, Action.PARAMETER_PRECISION);
  }

  /**
   * Returns the actions string representation:
   * 
   * @return (kick &lt;power&gt; &lt;direction&gt;)<br>
   *         <br>
   */
  @Override
  public String toString() {

    final StringBuffer buf = new StringBuffer();
    buf.append("(kick ");
    buf.append(this._power);
    buf.append(" ");
    buf.append(Vektor.normalize(this._direction));
    buf.append(")");
    return buf.toString();
  }

  /**
   * @return Returns the direction.
   */
  public double getDirection() {

    return this._direction;
  }

  /**
   * An action is worth sending if it effects the world.
   * 
   * @return true, if the power is greater 0.
   */
  @Override
  public boolean isWorthSending() {

    return this._power > 0;
  }

  /**
   * @return Returns the power.
   */
  public double getPower() {

    return this._power;
  }

  
  /**
   * Sets the direction of this KickAction
   * 
   * @param _direction the direction
   */
  public void setDirection(double _direction) {
  
    this._direction = RCMath.round(_direction, Action.PARAMETER_PRECISION);;
  }

  
  /**
   * Sets the power of this KickAction
   * @param _power the power 
   */
  public void setPower(double _power) {
  
    this._power = RCMath.round(_power, Action.PARAMETER_PRECISION);;
  }

}
